var filmDetail={
    getDtail:async function () {
        var url="http://huruqing.cn:3000/api/film/getDetail"
        var strUrl=location.search
        var self=this
        $.ajax({
            type: "get",
            url: url,
            data: {
                filmId: strUrl.replace(/\?filmId=(.*)/,'$1')
                // filmId: filmId
            },
            dataType: "json",
            success: function (response) {
                if (response.code!='602') {
                    // console.log(response)
                    self.renderFilm(response.film)
                }else{
                    alert(response.msg)
                }
            }
        });
        // var dtail=await reques.get('film/getDetail')
        // var filmId= strUrl.replace(/\?filmId=(.*)/,'$1')
        // console.log(filmId)
        // console.log(dtail)
        // this.renderFilm(dtail.film,{filmId:filmId})

    },renderFilm(film){
        Date.prototype.toLocaleString = function() {
            // 补0   例如 2018/7/10  补完后为 2018-07-10
            function addZero(num) {
                if(num<10)
                return "0" + num;
                return num;
            }
            // 按自定义拼接格式返回
            return this.getFullYear() + "-" + addZero(this.getMonth() + 1) + "-" + addZero(this.getDate()) 
        };
        // 根据毫秒数构建 Date 对象
        var date = new Date(film.premiereAt*1000);
        // 按重写的自定义格式，格式化日期
        dateTime = date.toLocaleString();
        var str=`
        <div class="header">
            <div>
                <img class="pc100" src="${film.poster}">
            </div>
            <div class="flex jc-c ai-c"><a href="index.html"><i class="iconfont icon-changyongtubiao-fuben-24"></i></a></div>
        </div>
        <div class="plot pc100">
            <div class="text bg-fff mb-10">
                <div class="fd-fr jc-sb texttitle mb-10">
                    <p>
                        ${film.name}
                        <span class="fff f12">${film.filmType}</span>
                    </p>
                    <p class="f12 pj"><em class="f16">${film.grade}</em>分</p>
                </div>
                <div>
                    <p class="f666 f12 mt-5">剧情</p>
                    <p class="f666 f12 mt-5">${dateTime}.上映</p>
                    <p class="f666 f12 mt-5">${film.nation}|&nbsp;${film.runtime}分钟</p>
                </div>
                <p class="f12 f666 tilte">
                    ${film.synopsis}
                </p>
            </div>
            <div class="text bg-fff">
                <div class="fd-fr jc-sb texttitle mb-10">
                    <p>
                        演职人员
                    </p>
                </div>
                <ul class="fd-fr actors">
                </ul>
            </div>
        </div>
        <div class="fd-c foot fixed jc-c ai-c">
            <button class="fff">选座购票</button>
        </div>
        `
        document.querySelector('.dyxq').innerHTML=str
        this.actors(film.actors)
    },actors(list){
        var listActors='';
        list.forEach(item => {
            listActors+=`
            <li class="fd-c jc-c ai-c ml-5">
            <img src="${item.avatarAddress}">
            <p class="f12 mb-5">${item.name}</p>
            <p class="f12 f666">${item.role}</p>
            </li>
            `
        });
        document.querySelector('.actors').innerHTML=listActors

    }
}
filmDetail.getDtail()